package com.volvo.caretrack.mobile.feed.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.volvo.caretrack.mobile.exception.AuthException;
import com.volvo.caretrack.mobile.feed.IMachineManagerDesk;
import com.volvo.caretrack.mobile.model.auth.Session;
import com.volvo.caretrack.mobile.model.machine.Machine;
import com.volvo.caretrack.mobile.model.machine.MachinePosition;
import com.volvo.caretrack.mobile.model.machine.MachineType;
import com.volvo.caretrack.mobile.model.machine.SearchCondition;

/*
 * 
 * #this class is for demo purpose, since we do not have connection to Caretrack's backend services.
 */

public class DummyMachineManagerDesk implements IMachineManagerDesk {

	

	@Override
	public List<Machine> getMachines(Session session, SearchCondition condition) throws AuthException {
		//todo
//		if (session == null || StringUtils.isEmpty(session.getSessionID()))
//			throw new AuthException("Session expired");
		List<Machine> machineList = new ArrayList<Machine>();
		int limit = condition.getLimit();
		for (int i=1;i<=limit;i++) {
			machineList
					.add(new Machine()
							.setChassisNo("A30D007400" + i)
							.setName("API ART Machine " + i)
							.setType(
									new MachineType().setName("ART")
											.setGeneration("D"))
							.setModel("A30D").setBrand("Volvo"));
		}
		return machineList;
	}

	@Override
	public MachinePosition getPosition(Session session, String chassisNo) throws AuthException {
		//todo
//		if (session == null || StringUtils.isEmpty(session.getSessionID()))
//			throw new AuthException("Session expired");
		MachinePosition dummyPosition = new MachinePosition()
				.setChassisNo("EW200765006")
				.setLongitude(Float.valueOf("15.149416"))
				.setLatitude(Float.valueOf("56.976063"))
				.setAltitude(Float.valueOf("0"))
				.setTimestamp(new Date())
				.setReverseGeocoding("Somewhere in Sweden").setFuelLevel(10)
				.setState(0);
		return dummyPosition;
	}

}
